package cn.iocoder.yudao.module.wine.controller.admin.memberdeadline;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.wine.controller.admin.memberdeadline.vo.*;
import cn.iocoder.yudao.module.wine.dal.dataobject.memberdeadline.MemberDeadlineDO;
import cn.iocoder.yudao.module.wine.service.memberdeadline.MemberDeadlineService;

@Tag(name = "管理后台 - 会员期限")
@RestController
@RequestMapping("/wine/member-deadline")
@Validated
public class MemberDeadlineController {

    @Resource
    private MemberDeadlineService memberDeadlineService;

    @PostMapping("/create")
    @Operation(summary = "创建会员期限")
    @PreAuthorize("@ss.hasPermission('wine:member-deadline:create')")
    public CommonResult<Long> createMemberDeadline(@Valid @RequestBody MemberDeadlineSaveReqVO createReqVO) {
        return success(memberDeadlineService.createMemberDeadline(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新会员期限")
    @PreAuthorize("@ss.hasPermission('wine:member-deadline:update')")
    public CommonResult<Boolean> updateMemberDeadline(@Valid @RequestBody MemberDeadlineSaveReqVO updateReqVO) {
        memberDeadlineService.updateMemberDeadline(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除会员期限")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('wine:member-deadline:delete')")
    public CommonResult<Boolean> deleteMemberDeadline(@RequestParam("id") Long id) {
        memberDeadlineService.deleteMemberDeadline(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得会员期限")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('wine:member-deadline:query')")
    public CommonResult<MemberDeadlineRespVO> getMemberDeadline(@RequestParam("id") Long id) {
        MemberDeadlineDO memberDeadline = memberDeadlineService.getMemberDeadline(id);
        return success(BeanUtils.toBean(memberDeadline, MemberDeadlineRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得会员期限分页")
    @PreAuthorize("@ss.hasPermission('wine:member-deadline:query')")
    public CommonResult<PageResult<MemberDeadlineRespVO>> getMemberDeadlinePage(@Valid MemberDeadlinePageReqVO pageReqVO) {
        PageResult<MemberDeadlineRespVO> pageResult = memberDeadlineService.getMemberDeadlinePage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, MemberDeadlineRespVO.class));
    }

//    @GetMapping("/export-excel")
//    @Operation(summary = "导出会员期限 Excel")
//    @PreAuthorize("@ss.hasPermission('wine:member-deadline:export')")
//    @OperateLog(type = EXPORT)
//    public void exportMemberDeadlineExcel(@Valid MemberDeadlinePageReqVO pageReqVO,
//              HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<MemberDeadlineDO> list = memberDeadlineService.getMemberDeadlinePage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "会员期限.xls", "数据", MemberDeadlineRespVO.class,
//                        BeanUtils.toBean(list, MemberDeadlineRespVO.class));
//    }

}
